<?php
require_once('libraryfiles/config.php');
$content = 'product_list.php';

$include='
<link rel="stylesheet" type="text/css" href="css/simple.css" />
';

require_once TMP_USER_PATH;
?>
<?php
		$select = mysql_query("
				SELECT p.product_name, img.thumbnail, pip.price, 
				pip.country_id,p.id
				FROM `tblproduct` AS p LEFT JOIN `tblimage` AS img ON p.id = img.product_id
				LEFT JOIN `tblproduct_in_pharmacy` AS pip ON p.id = pip.product_id
		");
?>
<div class="title">Category: Health</div>
<table border="0" style="padding:0px 10px">
	<?php
		while($data=mysql_fetch_assoc($select)){
		$pharmacy= mysql_query("SELECT COUNT(DISTINCT pharmacy_id) AS pid
		FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." AND country_id=".$data['country_id']);
		
		$price=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." AND country_id=".$data['country_id']." ORDER BY price ASC LIMIT 0,1");
		$myprice=mysql_fetch_assoc($price);
		$price1=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." AND country_id=".$data['country_id']." ORDER BY price DESC LIMIT 0,1");
		$myprice1=mysql_fetch_assoc($price1);
	?>
	<tr>
    	<td width="10%"><img class="product_list_image" src="<?php echo W_S_IMAGES_DIR.$data['thumbnail'] ?>" /></td>
        <td width="66%">
        	<div class="product_list_name" style="padding-left:10px;"><?php echo $data['product_name'] ?></div>
            <div class="make_in" style="padding-left:10px;">
            	( Made in <?php echo getCountryName($data['country_id']);?> )
            </div>
        </td>
        <td width="34%">
        	<div class="product_list_price">Price:</div>
            <div class="price">
				<?php 
					if($myprice['price']==$myprice1['price']){
						echo $myprice['price'];
					}
					else{
						echo $myprice['price'] .' - '. $myprice1['price'] ; 
					}
                ?>
            </div>
            <div style="clear:both"></div><div class="quantity_pharmacies">
            	(<?php 
				$data1=mysql_fetch_assoc($pharmacy);
					echo $data1['pid'];
				 ?> Pharmacies)
            </div>
         </td>
    </tr>
    <tr><td colspan="3" background="images/line_product_list.jpg" height="0px"></td></tr>
    <?php  }  ?>
</table>